import requests
import re
import base64

base_url = "https://news.sina.cn/zt_d/yiqing0121"
headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                      'Chrome/86.0.4240.75 Safari/537.36 '
    }
response = requests.get(url=base_url, headers=headers)
content = response.text
# print(content)
# 提取base64加密的字符串
pattern = r'base64,(.*?)\)'
data = re.findall(pattern, content, re.S)[0]
print(data)
# base64编码后的二进制图片文件

# base64解码(解成二进制串)
temp = base64.b64decode(data)
print(temp)
'iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAIvklEQVR4Xu3bv25dRRDH8XMudDY1FDwDFTwADUjIsUQJ4hHSgqKkTQJSSt4BeidBgoYHIA9CGpqY1hcZHMUxvvfun5nZ2Zlv2uzOnP3NfOQizrrwhwRIYGcCK9mQAAnsTgAgbAcJ7EkAIKwHCQCEHSCBtgRS\/wQ5vf\/q07PH7\/3eFh23MiSQFside+dfLev2p2XZ3Hn6\/dGzDMPmjfUJpATyBsfrwEBSvzo5bqQD8n8cIMmx6m2vTAVkNw6QtK1P\/FtpgBzGAZL4617\/whRAynGApH6FYt8ID6QeB0hir3zd60IDaccBkro1ins6LJB+HCCJu\/blLwsJRA4HSMpXKebJcEDkcYAk5uqXvSoUED0cIClbp3inwgDRxwGSeOt\/+EUhgNjhAMnhlYp1IgSQ0wd\/f7y9uPjDdjT8gqNt3mO6hQByGd1\/SLbPlmX7vl2UILHLekynMEBAMmaBoncNBQQk0dfV\/n3hgIDEfokidwwJBCSRV9b2bWGBgMR2kaJ2Cw0EJFHX1u5d4YGAxG6ZInZKAQQkEVfX5k1pgIDEZqGidUkFBCTR1lf\/PemAgER\/qSJ1SAkEJJFWWPctaYGARHexolRPDQQkUdZY7x3pgYBEb7kiVAbI1RT5\/yQR1ln+DQC5lilI5Bds9ooAuTFBkMy+0rLfD5Bb8gSJ7JLNXA0gO6YHkpnXWu7bAbInS5DILdqslQByYHIgmXW1Zb4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.net/static/img/404.png'
# 写入jpg文件
with open('hot2.jpg', 'wb') as f:
    f.write(t)

